/**
 *
 * Created by fuhao on 15/9/8.
 */
function UserContract() {
    this.method, this.action;
}

UserContract.prototype.submit = function () {
    var objThis = this;
    var params = $('#inputForm').serializeJson();
    $.ajax({
        async: true,
        type: 'post',
        url: basePath + '/' + objThis.action + "/" + objThis.method,
        data: params,
        beforeSend: function () {
            var $this;
            try {
                $('#inputForm').find('input:not(:disabled)').each(function () {
                    $this = $(this);
                    var _value = $this.val();
                    if (isEmpty(_value) || _value.length < parseInt($this.attr('min'))) {
                        throw $this.attr('placeholder');
                    }
                });
            } catch (e) {
                $.messager.alert('提示', e);
                objThis.binkSubmitClick();
                return false;
            }
            return true;
        },
        success: function (data) {
            objThis.binkSubmitClick();
            validateReqStatus(data, function () {
                $.messager.alert('提示', '更新成功');
            });
        },
        error: function () {
            objThis.binkSubmitClick();
            $.messager.alert('提示', '更新失败');
        }
    });
};

UserContract.prototype.binkSubmitClick = function () {
    var objThis = this;
    $('#submitBtn').one('click', function () {
        objThis.submit();
    });
};

UserContract.prototype.init = function () {
    var objThis = this;
    objThis.binkSubmitClick();
};

$(document).ready(function () {
    var userContract = new UserContract();
    userContract.action = "userContract";
    userContract.method = "update";
    userContract.init();
    tabToggle();
});
